<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .financial-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .flow-btn-export {
    margin-bottom: 10px;
    margin-top: 10px;
    /* margin-top: -46px; */
    /* float: right; */
  }
  .sale-tag {
    width: 180px;
    height: 40px;
    font-size: 13px;
    text-align: center;
    margin-right: 15px;
    line-height: 40px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>服务费统计</span>
    </div>
    <div class="line"></div>
    <financial-form
      :title='title'
      class="financial-form"
      @on-success-valid="handleSubmit">
    </financial-form>
    <div>
      <div>
        <Tag color="orange" class="sale-tag">服务费余额：{{accountBalance[0] && accountBalance[0].service ? accountBalance[0].service : '0'}}</Tag>
      </div>
    </div>
    <btn-export :tableData="serviceFeeList" :tableTitle="columns" :title="title" class="flow-btn-export"></btn-export>
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      :loading="loading"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import FinancialForm from '_c/financial-form'
import BtnExport from '_c/btn-export'
import TablePage from '_c/table-page'
export default {
  components: {
    FinancialForm,
    TablePage,
    BtnExport
  },
  data () {
    return {
      page: 1,
      title: '财务管理服务费统计',
      rows: 20,
      postData: null,
      loading: true,
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '交易日期',
          key: 'ctime',
          minWidth: 150,
          align: 'center'
        },
        // {
        //   title: '结算方式',
        //   key: 'type0',
        //   // width: 160,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('span', params.row.type0 === 0 ? '服务费充值' : params.row.type0 === 11 ? '短信发送' : '-')
        //   }
        // },
        {
          title: '短信账单',
          key: 'money',
          minWidth: 100,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.money)
          }
        },
        {
          title: '备注',
          key: 'des',
          minWidth: 250,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.des ? params.row.des : '-')
          }
        }
        // {
        //   title: '操作',
        //   key: 'cz',
        //   width: 200,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small',
        //           ghost: 'ghost'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         },
        //         on: {
        //           click: () => {
        //             this.handleClick(params.row.id, params.row)
        //           }
        //         }
        //       }, '详情')
        //     ])
        //   }
        // }
      ]
    }
  },
  computed: {
    ...mapState({
      serviceFeeList: state => state.serviceFee.serviceFeeList,
      accountBalance: state => state.commission.accountBalance,
      dataCount: state => state.serviceFee.serviceFeeDataCount,
      historyData: state => state.serviceFee.serviceFeeHistoryData,
      pageSize: state => state.serviceFee.serviceFeePageSize
    })
  },
  methods: {
    ...mapActions([
      'getServiceFeeList',
      'getAccountBalanceData',
      'changeServiceFeePage',
      'changeServiceFeePageSize'
    ]),
    handleSubmit (playload) {
      // console.log(playload)
      this.loading = true
      this.postData = {
        ctime: playload.ctime,
        type0: playload.type0,
        type: 1
      }
      this.getServiceFeeList({
        ...this.postData,
        rows: this.rows
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePage (index) {
      this.loading = true
      this.page = index
      this.changeServiceFeePage(index)
      this.getServiceFeeList({
        type: 1,
        page: index,
        rows: this.rows,
        ...this.postData
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    },
    changePageSize (value) {
      this.loading = true
      this.rows = value
      this.changeServiceFeePageSize(value)
      this.changePage(this.page)
      this.getServiceFeeList({
        type: 1,
        rows: value,
        ...this.postData
      }).then((res) => {
        if (res.data.state === '000') {
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getServiceFeeList({
      type: 1
    }).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
    this.getAccountBalanceData({})
  }
}
</script>
